from datetime import datetime
import pandas as pd
from pathlib import Path
import plotly
import plotly.express as px
import numpy as np
from statsmodels.tsa.api import VAR
import urllib.request
plotly.offline.init_notebook_mode()
NOW = datetime.now()
TODAY = NOW.date()
print('Aktualisiert:', NOW)
Aktualisiert: 2022-05-11 14:02:26.493859
STATE_NAMES = ['Burgenland', 'Kärnten', 'Niederösterreich',
'Oberösterreich', 'Salzburg', 'Steiermark',
'Tirol', 'Vorarlberg', 'Wien']
# TODO: Genauer recherchieren!
EVENTS = {'1. Lockdown': (np.datetime64('2020-03-20'), np.datetime64('2020-04-14'),
'red', 'inside top left'),
'1. Maskenpflicht': (np.datetime64('2020-03-30'), np.datetime64('2020-06-15'),
'yellow', 'inside bottom left'),
'2. Maskenpflicht': (np.datetime64('2020-07-24'), np.datetime64(TODAY),
'yellow', 'inside bottom left'),
'1. Soft Lockdown': (np.datetime64('2020-11-03'), np.datetime64('2020-11-17'),
'orange', 'inside top left'),
'2. Lockdown': (np.datetime64('2020-11-17'), np.datetime64('2020-12-06'),
'red', 'inside top left'),
'2. Soft Lockdown': (np.datetime64('2020-12-06'), np.datetime64('2020-12-27'),
'orange', 'inside top left'),
'Weihnachten 2020': (np.datetime64('2020-12-24'), np.datetime64('2020-12-27'),
'blue', 'inside top left'),
'3. Lockdown': (np.datetime64('2020-12-27'), np.datetime64(TODAY),
'red', 'inside top left')}
def load_data(URL, date_columns):
data_file = Path(URL).name
try:
# Only download the data if we don't have it, to avoid
# excessive server access during local development
with open(data_file):
print("Using local", data_file)
except FileNotFoundError:
print("Downloading", URL)
urllib.request.urlretrieve(URL, data_file)
return pd.read_csv(data_file, sep=';', parse_dates=date_columns, infer_datetime_format=True, dayfirst=True)
raw_data = load_data("https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv", [0])
additional_data = load_data("https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv", [0, 2])
Downloading https://covid19-dashboard.ages.at/data/CovidFaelle_Timeline.csv Downloading https://covid19-dashboard.ages.at/data/CovidFallzahlen.csv
cases = raw_data.query("Bundesland == 'Österreich'")
cases.insert(0, 'AnzahlFaelle_avg7', cases.AnzahlFaelle7Tage / 7)
time = cases.Time
tests = additional_data.query("Bundesland == 'Alle'")
tests.insert(2, 'TagesTests', np.concatenate([[np.nan], np.diff(tests.TestGesamt)]))
tests.insert(3, 'TagesTests_avg7', np.concatenate([[np.nan] * 7, (tests.TestGesamt.values[7:] - tests.TestGesamt.values[:-7])/7]))
tests.insert(0, 'Time', tests.MeldeDatum)
fig = px.line(cases, x='Time', y=["AnzahlFaelle", "AnzahlFaelle_avg7"], log_y=True, title="Fallzahlen")
fig.add_scatter(x=tests.Time, y=tests.TagesTests, name='Tests')
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
all_data = tests.merge(cases, on='Time', how='outer')
all_data.insert(1, 'PosRate', all_data.AnzahlFaelle / all_data.TagesTests)
all_data.insert(1, 'PosRate_avg7', all_data.AnzahlFaelle_avg7 / all_data.TagesTests_avg7)
fig = px.line(all_data, x='Time', y=['PosRate', 'PosRate_avg7'], log_y=False, title="Anteil Positiver Tests")
for name, (begin, end, color, pos) in EVENTS.items():
fig.add_vrect(x0=begin, x1=end, name=name, fillcolor=color, opacity=0.2,
annotation={'text': name}, annotation_position=pos)
fig.show()
states = []
rates = []
for state_name, state_data in raw_data.groupby('Bundesland'):
x = np.log2(state_data.AnzahlFaelle7Tage)
rate = 2**np.array(np.diff(x))
rates.append(rate)
states.append(state_name)
growth = pd.DataFrame({n: r for n, r in zip(states, rates)})
fig = px.line(growth, x=time[1:], y=STATE_NAMES, title='Wachstumsrate')
fig.update_layout(yaxis=dict(range=[0.25, 4]))
fig.show()
/usr/share/miniconda/lib/python3.8/site-packages/pandas/core/series.py:726: RuntimeWarning: divide by zero encountered in log2 /usr/share/miniconda/lib/python3.8/site-packages/numpy/lib/function_base.py:1280: RuntimeWarning: invalid value encountered in subtract
model = VAR(growth[150:][STATE_NAMES])
res = model.fit(1)
res.summary()
Summary of Regression Results
==================================
Model: VAR
Method: OLS
Date: Wed, 11, May, 2022
Time: 14:02:32
--------------------------------------------------------------------
No. of Equations: 9.00000 BIC: -49.2453
Nobs: 653.000 HQIC: -49.6234
Log likelihood: 8031.16 FPE: 2.21207e-22
AIC: -49.8630 Det(Omega_mle): 1.92928e-22
--------------------------------------------------------------------
Results for equation Burgenland
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.323641 0.061212 5.287 0.000
L1.Burgenland 0.104643 0.039031 2.681 0.007
L1.Kärnten -0.109910 0.020463 -5.371 0.000
L1.Niederösterreich 0.194605 0.081389 2.391 0.017
L1.Oberösterreich 0.121842 0.080433 1.515 0.130
L1.Salzburg 0.257132 0.041451 6.203 0.000
L1.Steiermark 0.045276 0.054446 0.832 0.406
L1.Tirol 0.103666 0.043913 2.361 0.018
L1.Vorarlberg -0.063652 0.038856 -1.638 0.101
L1.Wien 0.028440 0.071192 0.399 0.690
======================================================================================
Results for equation Kärnten
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.049883 0.130736 0.382 0.703
L1.Burgenland -0.032751 0.083362 -0.393 0.694
L1.Kärnten 0.040494 0.043705 0.927 0.354
L1.Niederösterreich -0.186573 0.173831 -1.073 0.283
L1.Oberösterreich 0.449410 0.171789 2.616 0.009
L1.Salzburg 0.284450 0.088531 3.213 0.001
L1.Steiermark 0.107605 0.116285 0.925 0.355
L1.Tirol 0.312050 0.093788 3.327 0.001
L1.Vorarlberg 0.022050 0.082989 0.266 0.790
L1.Wien -0.038440 0.152052 -0.253 0.800
======================================================================================
Results for equation Niederösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.189189 0.031409 6.023 0.000
L1.Burgenland 0.089965 0.020027 4.492 0.000
L1.Kärnten -0.008033 0.010500 -0.765 0.444
L1.Niederösterreich 0.249456 0.041762 5.973 0.000
L1.Oberösterreich 0.154709 0.041272 3.749 0.000
L1.Salzburg 0.042260 0.021269 1.987 0.047
L1.Steiermark 0.025968 0.027937 0.930 0.353
L1.Tirol 0.086219 0.022532 3.826 0.000
L1.Vorarlberg 0.054298 0.019938 2.723 0.006
L1.Wien 0.117330 0.036530 3.212 0.001
======================================================================================
Results for equation Oberösterreich
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.111875 0.031539 3.547 0.000
L1.Burgenland 0.045885 0.020110 2.282 0.023
L1.Kärnten -0.014112 0.010544 -1.338 0.181
L1.Niederösterreich 0.181686 0.041936 4.332 0.000
L1.Oberösterreich 0.328325 0.041443 7.922 0.000
L1.Salzburg 0.101425 0.021358 4.749 0.000
L1.Steiermark 0.109991 0.028053 3.921 0.000
L1.Tirol 0.096459 0.022626 4.263 0.000
L1.Vorarlberg 0.059837 0.020021 2.989 0.003
L1.Wien -0.022215 0.036682 -0.606 0.545
======================================================================================
Results for equation Salzburg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.114223 0.058724 1.945 0.052
L1.Burgenland -0.044112 0.037445 -1.178 0.239
L1.Kärnten -0.046217 0.019632 -2.354 0.019
L1.Niederösterreich 0.141964 0.078082 1.818 0.069
L1.Oberösterreich 0.162551 0.077165 2.107 0.035
L1.Salzburg 0.281115 0.039767 7.069 0.000
L1.Steiermark 0.056142 0.052233 1.075 0.282
L1.Tirol 0.164571 0.042128 3.906 0.000
L1.Vorarlberg 0.095886 0.037277 2.572 0.010
L1.Wien 0.076079 0.068299 1.114 0.265
======================================================================================
Results for equation Steiermark
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.060074 0.046262 1.299 0.194
L1.Burgenland 0.031605 0.029498 1.071 0.284
L1.Kärnten 0.051390 0.015465 3.323 0.001
L1.Niederösterreich 0.204382 0.061512 3.323 0.001
L1.Oberösterreich 0.319275 0.060789 5.252 0.000
L1.Salzburg 0.040955 0.031328 1.307 0.191
L1.Steiermark 0.006208 0.041149 0.151 0.880
L1.Tirol 0.131061 0.033188 3.949 0.000
L1.Vorarlberg 0.065903 0.029367 2.244 0.025
L1.Wien 0.089932 0.053805 1.671 0.095
======================================================================================
Results for equation Tirol
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.173665 0.055494 3.129 0.002
L1.Burgenland 0.005068 0.035385 0.143 0.886
L1.Kärnten -0.065172 0.018551 -3.513 0.000
L1.Niederösterreich -0.100442 0.073786 -1.361 0.173
L1.Oberösterreich 0.207491 0.072919 2.845 0.004
L1.Salzburg 0.053890 0.037579 1.434 0.152
L1.Steiermark 0.240935 0.049360 4.881 0.000
L1.Tirol 0.500303 0.039810 12.567 0.000
L1.Vorarlberg 0.059455 0.035226 1.688 0.091
L1.Wien -0.072650 0.064542 -1.126 0.260
======================================================================================
Results for equation Vorarlberg
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.146566 0.061585 2.380 0.017
L1.Burgenland 0.004533 0.039269 0.115 0.908
L1.Kärnten 0.060496 0.020588 2.938 0.003
L1.Niederösterreich 0.183343 0.081885 2.239 0.025
L1.Oberösterreich -0.056580 0.080923 -0.699 0.484
L1.Salzburg 0.205515 0.041704 4.928 0.000
L1.Steiermark 0.134386 0.054778 2.453 0.014
L1.Tirol 0.067961 0.044180 1.538 0.124
L1.Vorarlberg 0.143538 0.039093 3.672 0.000
L1.Wien 0.111961 0.071626 1.563 0.118
======================================================================================
Results for equation Wien
======================================================================================
coefficient std. error t-stat prob
--------------------------------------------------------------------------------------
const 0.377147 0.036239 10.407 0.000
L1.Burgenland -0.000999 0.023107 -0.043 0.966
L1.Kärnten -0.021858 0.012115 -1.804 0.071
L1.Niederösterreich 0.212451 0.048185 4.409 0.000
L1.Oberösterreich 0.227156 0.047619 4.770 0.000
L1.Salzburg 0.038570 0.024540 1.572 0.116
L1.Steiermark -0.013927 0.032233 -0.432 0.666
L1.Tirol 0.094689 0.025997 3.642 0.000
L1.Vorarlberg 0.053500 0.023004 2.326 0.020
L1.Wien 0.035309 0.042148 0.838 0.402
======================================================================================
Correlation matrix of residuals
Burgenland Kärnten Niederösterreich Oberösterreich Salzburg Steiermark Tirol Vorarlberg Wien
Burgenland 1.000000 0.036412 0.114041 0.173395 0.142970 0.100615 0.085009 0.040186 0.210010
Kärnten 0.036412 1.000000 -0.020546 0.134755 0.052615 0.089753 0.440982 -0.060223 0.093215
Niederösterreich 0.114041 -0.020546 1.000000 0.323858 0.128266 0.285389 0.073758 0.162882 0.296135
Oberösterreich 0.173395 0.134755 0.323858 1.000000 0.221735 0.309674 0.167808 0.150916 0.251482
Salzburg 0.142970 0.052615 0.128266 0.221735 1.000000 0.129206 0.097700 0.116186 0.130883
Steiermark 0.100615 0.089753 0.285389 0.309674 0.129206 1.000000 0.137578 0.117838 0.050531
Tirol 0.085009 0.440982 0.073758 0.167808 0.097700 0.137578 1.000000 0.069728 0.148066
Vorarlberg 0.040186 -0.060223 0.162882 0.150916 0.116186 0.117838 0.069728 1.000000 0.007568
Wien 0.210010 0.093215 0.296135 0.251482 0.130883 0.050531 0.148066 0.007568 1.000000